from django.shortcuts import render

# Create your views here.
from rest_framework.viewsets import GenericViewSet
from utils.view import CommonListModelMixin, CommonCreateModelMixin, CommonUpdateModelMixin

from .models import ShopCar
from .serializer import ShopCarSerializer, UpdateCarSerializer
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.viewsets import ModelViewSet
from rest_framework_jwt.authentication import JSONWebTokenAuthentication
from rest_framework.permissions import IsAuthenticated



class ShopCarView(ModelViewSet, CommonListModelMixin, CommonCreateModelMixin):
    queryset = ShopCar.objects.all().filter(is_delete=False, is_show=True).order_by('-created_time')
    serializer_class = ShopCarSerializer
    authentication_classes = [JSONWebTokenAuthentication]
    permission_classes = [IsAuthenticated]
    filter_backends = [DjangoFilterBackend]
    filterset_fields = ['user_id', 'goods_id']



class UpdateCarView(GenericViewSet, CommonUpdateModelMixin):
    queryset = ShopCar.objects.all()
    serializer_class = UpdateCarSerializer
    authentication_classes = [JSONWebTokenAuthentication]
    permission_classes = [IsAuthenticated]
    filter_backends = [DjangoFilterBackend]
    filterset_fields = ['user_id']

